import javax.swing.JOptionPane;

public class studentScore {
    public static void main(String[] args) {
        int[] score = new int[100];
        int count = 0;
        int sum = 0;
        double average = 0;
        try
        {
            while(true)
            {
                String input = JOptionPane.showInputDialog("请输入学生的成绩");
                int num = Integer.parseInt(input);
                if(num == -1)
                    break;
                score[count] = num;
                sum += num;
                count++;
            }
            average = (double) sum / (count);
            System.out.println("总分 :" + sum);
            System.out.println("平均分 :" + average);
        }catch (NumberFormatException e)
        {
            System.out.println("输入的不是有效数字，请重新输入！");
        }catch (IndexOutOfBoundsException e)
        {
            System.out.println("数组下标越界，可能输入的成绩过多超过数组容量！");
        }catch (ArithmeticException e)
        {
            System.out.println("计算平均分出现算数异常，可能是除数为 0 ！");
        }
    }
}
